<?php

/**
 * Flickr Photosets - Geotagged Photos Page
 * Displays the user's geotagged photos.
 * 
 * @author Brad Dougherty <bdougherty@gmail.com>
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License 3.0
 */

/*
Require the function library
This will include all other necessary files
*/
require_once 'lib.php';

/*
Initialize Flickr Photosets and Flickr
*/
$fp = new FlickrPhotosetsCanvas();

// If the user has disabled photosets
if (!$fp->config['enable_gallery_geotagged']) {
	if ($fp->config['enable_gallery_photostream']) {
		$fp->facebook->redirect($fp->canvas_url.'/photos/'.$fp->uid.'/');
	}
	else if ($fp->config['enable_gallery_photosets']) {
		$fp->facebook->redirect($fp->canvas_url.'/photos/'.$fp->uid.'/sets/');
	}
	else {
		$fp->error(FlickrPhotosetsErrors::$geotagged_disabled);
	}
}

// To get photos with geo data, we have to authenticate
$fp->flickr->setToken($fp->config['flickr_token']);

// We will get only their public photos, unless they are set for private photos.
if ($fp->config['privacy_filter'] == $fp->privacy_filter['private']) {
	$photos = $fp->flickr->photos_getWithGeoData(array(
		'per_page'       => $fp->photos_per_page,
		'page'           => $fp->page,
		'extras'         => 'date_upload, media',
	));
}
else {
	$photos = $fp->flickr->photos_getWithGeoData(array(
		'privacy_filter' => $fp->privacy_filter['public'],
		'per_page'       => $fp->photos_per_page,
		'page'           => $fp->page,
		'extras'         => 'date_upload, media',
	));
}

// Get some counts
$photo_count = $photos['total'];
$page_count = $photos['pages'];

// Get the first and last photo
$first_photo = 1 + ($fp->photos_per_page * ($fp->page - 1));
$last_photo = $first_photo + ($fp->photos_per_page - 1);
$last_photo = ($last_photo > $photo_count) ? $photo_count : $last_photo;

?>

<fb:title><?=$fp->get_name_fbml(true)?> Geotagged Photos</fb:title>
<?=$fp->get_stylesheet('geotagged')?>

<?=$fp->get_header('geotagged')?>

<?php if ($photo_count < 1) {
	$fp->error(FlickrPhotosetsErrors::$no_geotagged_photos);
} else { ?>
	<div id="photo_header" class="clearfix">
		<div class="summary">
			Showing <?=$first_photo?> to <?=$last_photo?> of <?=$photo_count?> geotagged photos
			<span class="pipe">|</span>
			<a href="<?=$fp->flickr->urls_getUserPhotos($fp->nsid)?>map/">View Map on Flickr</a>
		</div>	
		<?=Pager::getPager($fp->page, $page_count, $fp->canvas_url.'/photos/'.$fp->uid.'/geo/')?>
	</div>
	
	<div class="photo_grid">
		<table>
			<tr>
				<?php $i = 0;
				foreach ($photos['photo'] as $photo): ?>
					<td>
						<a href="<?=$fp->canvas_url?>/photos/<?=$fp->uid?>/<?=$photo['id']?>/">
							<div class="thumb">
							<?php if ($photo['media'] == 'video') { ?>
								<img src="http://l.yimg.com/g/images/video_play_icon_medium.png.v1" class="video_icon" />
							<?php } ?>
							<fb:user-agent includes="ie 6">
								<img src="<?=$fp->flickr->buildPhotoUrl($photo, 'thumbnail')?>" alt="<?=$photo['title']?>" title="<?=$photo['title']?>" />
							</fb:user-agent>
							<fb:user-agent excludes="ie 6">
								<img src="<?=$fp->flickr->buildPhotoUrl($photo, 'small')?>" alt="<?=$photo['title']?>" title="<?=$photo['title']?>" />
							</fb:user-agent>
							</div>
						</a>
					</td>
				<?php $i++;
				echo ($i % 5 == 0) ? '</tr><tr>' : ''; ?>
				<?php endforeach; ?>
			</tr>
		</table>	
	</div>
	
	<div id="photo_footer_bar" class="bar clearfix footer_bar">
		<?=Pager::getPager($fp->page, $page_count, $fp->canvas_url.'/photos/'.$fp->uid.'/geo/')?>
	</div>
<?php } ?>

<?=$fp->echo_footer(true)?>